﻿<%@ Page Language="C#" MasterPageFile="~/Templates/top.master" AutoEventWireup="true"
    CodeFile="cart.aspx.cs" Inherits="cart" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:Panel ID="panelNoCart" runat="server" CssClass="divDisplayN">
        <div id="cart-none-msg">
            <div class="CartNav clearfix" style="background-color: #ffffff;">
                <div class="floatLeft">
                    <img alt="购物流程--查看购物车" src="img/themes/cartnav-step1.gif" />
                </div>
                <div class="floatRight">
                    <img src="img/themes/cartnav-cart.gif" />
                </div>
            </div>
            <div class="note" style="border-width: 1px;">
                <h3>
                    购物车目前没有加入任何商品!</h3>
                <ul class="list">
                    <li><a href="/">继续挑选商品»»</a> </li>
                    <li><a href="javascript:opener=null;window.close();">关闭此页面</a> </li>
                </ul>
            </div>
        </div>
    </asp:Panel>
    <asp:Panel ID="panelYesCart" runat="server">
        <div id="cart-index" class="CartWrap">
            <table width="100%">
                <tr style="height: 80px;">
                    <td valign="top" style="background-color: #ffffff;">
                        <img alt="购物流程--查看购物车" src="img/themes/cartnav-step1.gif" /></td>
                    <td valign="top" style="background-color: #ffffff;">
                        <img src="img/themes/cartnav-cart.gif" /></td>
                </tr>
            </table>
            <div id="cart-items" class="section">
                <div id="cartItems" class="FormWrap" style="padding: 7px;">
                    <h3>
                        已放入购物车的商品:</h3>
                    请在此确认你要购买的商品
                    <div id="goodsbody" class="division">
                        <table id="tblCarts" class="liststyle" width="100%" cellspacing="0" cellpadding="1">
                            <tr class="tableHeader">
                                <td style="width: 53px">
                                    <input id="SelectAll" type="checkbox" value="" onclick="SelectAllProduct(this)" /><label
                                        for="SelectAll">全选</label>
                                </td>
                                <td style="width: 80px">
                                    图片</td>
                                <td>
                                    商品名称</td>
                                <td style="width: 50px">
                                    尺码</td>
                                <td style="width: 50px">
                                    颜色</td>
                                <td style="width: 80px">
                                    销售价格</td>
                                <td style="width: 80px">
                                    优惠价格</td>
                                <td style="width: 80px">
                                    数量</td>
                                <td style="width: 80px">
                                    小计</td>
                                <td style="width: 54px">
                                </td>
                            </tr>
                            <%= strConent%>
                        </table>
                        <table style="width: 100%;">
                            <tr>
                                <td align="right" style="font-size: 14px; color: #000;">
                                    商品总额：
                                </td>
                                <td class="totalprice price1" style="width: 150px;" align="left">
                                    <div id="totalPrice">
                                        ￥334</div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="CartBtn clearfix" style="margin-bottom: 5px;width:100%;">
                    <div class="span-auto">
                        <a class="actbtn btn-return" href="./" target="_blank">«继续购物</a>
                    </div>
                    <div class="span-auto">
                        <a id="clearCart" class="actbtn btn-clearcat" href="javascript:DeleteAllCart(this);">
                            清空购物车</a>
                    </div>
                    <div class="span-auto floatRight">
                        <input type="button" onclick="return formSubmit();" class="actbtn btn-next" value="下单结算»" />
                    </div>
                </div>
            </div>
            <div style="position: absolute; z-index: 500; visibility: hidden; opacity: 0; border: 1px solid rgb(102, 102, 102);
                left: 250px; top: -38px;">
                <img src="http://www.umishop.com.cn/images/goods/20121030/236a5605c8b854e7.jpg" style="cursor: pointer;
                    border: 1px solid rgb(255, 255, 255);" />
            </div>
        </div>
    </asp:Panel>

    <script language="javascript" src="js/jquery-1.4.1.js"></script>

    <script language="javascript" type="text/javascript">
window.onload=function()
{
    var tbl = document.getElementById("tblCarts");
    var rows = tbl.rows
    if(rows.length>1)
    {
        for(var i=1;i<rows.length;i++)
        {
            SetOnePrice(rows[i]);
        }
    }
    GetAllPrice();
}
function SelectAllProduct(obj)
{
    var tbl = document.getElementById("tblCarts");
    var rows = tbl.rows
    if(rows.length>1)
    {
        for(var i=1;i<rows.length;i++)
        {
            var chk = rows[i].cells[0].getElementsByTagName("input")[0];
            chk.checked = obj.checked;
        }
    }
    GetAllPrice();
}
function checkTextboxValue(obj,min,max,defaultValue)
{
	var val=parseInt(obj.value);
	if(isNaN(val) || val>max || val<min) {
		obj.value=defaultValue;
	} else {
		obj.value=val;
	}
}
function ItemNumUpdate(obj)
{
    checkTextboxValue(obj,1,999,1);
     SetOnePrice(obj.parentNode.parentNode.parentNode);
    GetAllPrice();
}
function ItemNumAdd(obj,count)
{
    var objParent = obj.parentNode;
    var objText = objParent.getElementsByTagName("input")[0];
     
    var val = parseInt(objText.value) + count;
    objText.value = val;
    checkTextboxValue(objText,1,999,1);
    
    SetOnePrice(objParent.parentNode.parentNode);
    GetAllPrice();
}
function SetOnePrice(tr)
{
    var count = tr.cells[7].getElementsByTagName("input")[0].value;
    var price = tr.cells[6].innerHTML;
    tr.cells[8].innerHTML = parseInt(count) * parseInt(price);
}
function GetAllPrice()
{
    var tbl = document.getElementById("tblCarts");
    var rows = tbl.rows;
    if(rows.length>1)
    {
        var total=0;
        var price;
        for(var i=1;i<rows.length;i++)
        {
            var chk = rows[i].cells[0].getElementsByTagName("input")[0];
            if(chk.checked)
            {
                price = parseInt( rows[i].cells[8].innerHTML);
                total += price;
            }
        }
        document.getElementById("totalPrice").innerHTML = "￥" + total;
    }
    else
    {
        document.getElementById("totalPrice").innerHTML = "￥0";
    }
}
function DeleteRow(cartID)
{
    var tbl = document.getElementById("tblCarts");
    var rows = tbl.rows
    if(rows.length>1)
    {
        for(var i=1;i<rows.length;i++)
        {
            var rw = rows[i];
            if(rw.getAttribute("cartID")==cartID)
            {
                tbl.deleteRow(i);
                GetAllPrice();
                return;
            }
        }
    }
}
function DeleteAllRow()
{
    var tbl = document.getElementById("tblCarts");
    var rows = tbl.rows
    if(rows.length>1)
    { 
        for(var i=rows.length;i>1;i--)
        { 
             tbl.deleteRow(i-1);
        }
    }
}
function DeleteAllCart(obj)
{
    obj.disabled = true;
     $.ajax(
            {
              type: "POST",
              url: "ashx/CartDeleteAll.ashx" , 
              dataType: "json",
              success: function(data) {
                if(data.success)
                {
                    DeleteAllRow();
                }
                   
              },
              error:function(){
                alert("删除失败！");
              }
            }
     );
}
function DeleteCart(cartID,obj)
{ 
    obj.disabled = true;
     $.ajax(
            {
              type: "POST",
              url: "ashx/CartDelete.ashx" ,
              data: "cartID="+cartID,
              dataType: "json",
              success: function(data) {
                if(data.success)
                {
                    DeleteRow(data.msg);
                }
                   
              },
              error:function(){
                alert("删除失败！");
              }
            }
     );
         
            
}
function formSubmit()
{
    var frm = document.forms["formSubmit"];
    var tbl = document.getElementById("tblCarts");
    var rows = tbl.rows;
    var str="";
    var bHaveSel = false;
    if(rows.length>1)
    {
        var total=0;
        var price;
        for(var i=1;i<rows.length;i++)
        {
            var chk = rows[i].cells[0].getElementsByTagName("input")[0];
            var tr = rows[i];
            if(chk.checked)
            {
                var count = tr.cells[7].getElementsByTagName("input")[0].value;    
                var cartID = tr.getAttribute("cartID");
                str += cartID + "-" + count + ",";
                bHaveSel = true;
            }
        }
        
   }
   if(bHaveSel)
   {
        str = str.substring(0,str.length-1);
        window.location.href="Cart-selAdd.aspx?cartIds="+str;
        return true;
   }
   else 
   {
        alert("请选择一条记录！");
        return false;
   }
   
}
    </script>

</asp:Content>
